package com.io.client;

import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * Created by 41579 on 2016/12/23.
 */
public class NIOClient {
    public static void main(String[] args) throws Exception{
        SocketAddress sa = new InetSocketAddress("127.0.0.1",12345);
        SocketChannel sc = SocketChannel.open(sa);
        BufferedInputStream bin = new BufferedInputStream(System.in);
        byte[] b = new byte[1024];
        while(bin.read(b)>0){
            System.out.println(new String(b));
            ByteBuffer bbf = ByteBuffer.allocate(1024);
            bbf.put(b);
            bbf.flip();
            sc.write(bbf);
        }
        System.out.println("连接成功");
        sc.close();
    }
}
